<template>
	<view class="content" >
		<u-navbar :is-back="true" :border-bottom="false">
			<view  class="slot-wrap disfr-lr p15 f32" style="width: 98%;">
				<view class="slot-wrap-left"></view>
				<view class="slot-wrap-center">我的商机</view>
				<view class="slot-wrap-right">
					<view style=""
					@click="goPage" data-uri="/pages/business-create/business-create">
						<u-icon name="plus"  size="46"></u-icon>
					</view>
				</view>
			</view>
		</u-navbar>
		<my_navbar_ext height="50" bg-color="#ffffff">
			<u-tabs-swiper ref="tabs1" :current="current" @change="tabsChange" :list="tagsList" :is-scroll="false"></u-tabs-swiper>
		</my_navbar_ext>
		<view v-if="show_main" class="main" >

			<view v-for="(item,index) in list" :key="index" @click="goPage" :data-uri="'/pages/business-details/business-details?id='+item.id" class="bgf m20 pr f30 p20" style="border-radius: 4px;">
				
				<view @click.stop="threeClock" :data-id="item.id" :data-status="item.status" :data-classify_id="item.classify_id" class="pa" style="right: 10rpx;top:10rpx;">
					<u-icon name="more-dot-fill"  size="44"></u-icon>
				</view>
				<view class="f30 b mb10 disf" style="width: 600rpx;">
					<view v-if="item.coin_orders > 0 || item.orders > 0" class="mr5">
						<u-icon name="zhiding1" custom-prefix="qxl-icon" color="#2979ff" size="40"></u-icon>
					</view>
				    <view>{{item.title}}</view>
				</view>
				<view class="list disfr-lr">
					<view class="disf" style="width: 300rpx;">
						<view style="width: 46rpx;height: 46rpx;overflow: hidden;border-radius:4px;flex-shrink: 0;">
							<u-image width="48rpx" height="48rpx" :src="item.head_pic">
								<template v-slot:error>
									<image src="/static/image/default-user.png" style="width:48rpx;height: 48rpx;"></image>
								</template>
							</u-image>
						</view>
						<view class="ml10 toell pr" style="top:3rpx;">{{item.nickname}}</view>
					</view>
					<view class="col999">{{item.add_time_str}}</view>
				</view>
				
				<view class="p20 mt20" style="background: #f4f4f4;border-radius: 6px;min-height: 100rpx;">
					{{item.content}}
				</view>
				<view class="disfr-lr mt10 col999">
					<view class="mt5">
					<text style="color:#2979ff">{{item.classify_name}}</text>
					[<text v-if="item.status == 0">待审核</text><text v-else-if="item.status == 1">已审核</text><text v-else-if="item.status == 2">审核失败</text>]
					</view>
					<view class="disf">
						<view class="pr" style="top:8rpx;right: 30rpx;">{{item.area}}</view>
						<view>
							<u-icon name="eye-fill" size="44" style="position: relative;top:5rpx;"></u-icon>{{item.page_view}}
						</view>
					</view>
				</view>
				<view v-if="item.status == 2 && item.reason" class="f28" style="color:red;">原因:{{item.reason}}</view>
			</view>
			
            <view v-if="list.length <= 0 && not_load" style="text-align: center;margin-top: 40%;">
				<view><u-icon name="wuneirong-copy" custom-prefix="qxl-icon" color="#999999" size="100"></u-icon></view>
				<view class="f32 col999 mt20">什么都木有哦</view>
			</view>
			
		</view>
		
		<pageload :page_load="page_load" :next_page="next_page" :list="list" /><!--分页加载状态-->
	   <loading :loading="not_load"/><!--加载状态-->
	   <u-no-network tips="哎呀，网络信号丢失"></u-no-network><!--检测网络-->
	   
		<!--显示编辑或删除-->
		<u-popup v-model="showEditLayer" mode="bottom" border-radius="14" height="400rpx" :closeable="false">
			<view class="p30 f34" style="height: 300rpx;text-align: center;">
				<view style="height: 30rpx;"></view>
				
				<view v-if="editStatus == 0 || editStatus == 2" class="bbo edit-layer-bot" @click="therrUpdate">
					<u-icon name="edit-pen-fill" size="38" color="#666666"></u-icon><text>编辑</text>
				</view>
				<view v-else class="bbo edit-layer-bot col999">
					<u-icon name="edit-pen-fill" size="38"></u-icon><text>编辑</text>
				</view>
				
				<view class="bbo edit-layer-bot" @click="therrDelete">
					<u-icon name="trash-fill" size="38" color="#666666"></u-icon><text>删除</text>
				</view>
				<view class="edit-layer-bot col999" @click="showEditLayer=false">取消</view>
			</view>
		</u-popup><!--显示编辑或删除结束-->
			
	</view>
</template>

<script setup>
import { onLoad, onShow, onHide, onReachBottom,onPullDownRefresh } from '@dcloudio/uni-app';
import { ref } from 'vue';	
const show_main=ref(false);
const page_load=ref(false);
const not_load=ref(false);
const next_page=ref('');
const list=ref([]);
const tagsList=ref([{name:'全部'},{name:'待审核'},{name:'已审核'},{name:'审核失败'}]);
const current=ref(0);
//切换
const tabsChange=(e)=>{
	next_page.value='';
	current.value=e;
	let status=e;
	if(status == 0) {
		loadPage({},false);
	}else{
		status--;
		loadPage({status:status},false);
	}
};
//////////////////////////////////////////////
//显示修改&单个删除
const showEditLayer=ref(false);
const editDelId=ref('');
const editStatus=ref(0);
const editClassifyId=ref(0);
const threeClock=(e)=>{
	showEditLayer.value=true;
	editDelId.value=e.currentTarget.dataset.id;
	editStatus.value=e.currentTarget.dataset.status;
	editClassifyId.value=e.currentTarget.dataset.classify_id;
};
// 去修改
const therrUpdate=()=>{
	if(!editDelId.value) return;
	showEditLayer.value=false;
	let uri='/pages/business-create2/business-create2?id='+editDelId.value+'&classify_id='+editClassifyId.value+'&center=1';
	//console.log(uri);return;
	uni.$utils.goPage(uri,0);
};
// 去删除
const therrDelete=async ()=>{
	if(!editDelId.value) return;
	uni.$utils.showModal('确认执行删除操作？',1,async ()=>{
		not_load.value=false;
		showEditLayer.value=false;
		// 提交接口处理
		let ret=await uni.$get('/appapi-member-delpush',{id:editDelId.value});
		not_load.value=true;
		if(ret.error_code != 0){
			uni.$utils.showToast(ret.info);
			return;
		}
		uni.$utils.showToast('删除成功',0,()=>{
			loadPage({},false);
		});
	});
};
////////////////////////////////////////////////////////
//页面加载时
onLoad(async (options)=>{
    loadPage({},false);
});
const connected=(res)=>{
	
};
//页面显示时执行
onShow(()=>{
	
});
//页面隐藏时执行
onHide(()=>{
	
});

/**
 * 加载接口数据
 * @param {Object} options  参数,对像数组
 * @param {Object} isPage   是否加载大于1页
 */
const loadPage=async (options,isPage)=>{
	console.log('loadPage get');
	not_load.value=false;
	let ret = await uni.$get('/appapi-member-mypush',options);
	if(ret.error_code != 0){
		uni.$utils.showToast(ret.info);
		return;
	}
    page_load.value=false;
	show_main.value=true;
	not_load.value=true;
	next_page.value=ret.data.next_page;
	let tempString='';
	for(let i in ret.data.list){
		tempString=ret.data.list[i].content;
		tempString=tempString.replace(/\\n\\r/g,'');
		ret.data.list[i].content=uni.$utils.substr(tempString,52,'');
	}
	if(isPage) list.value=[...list.value,...ret.data.list];
	else list.value=ret.data.list;
};
onPullDownRefresh(()=>{
	//console.log('onPullDownRefresh');
	//not_load.value=false;
	setTimeout(()=>{
		loadPage({},false);
		uni.stopPullDownRefresh();
	}, 1000);
});
//上拉触底加载分页
onReachBottom(()=>{
	if (!next_page.value) return;
	if (page_load.value) return;
	page_load.value=true;
	setTimeout(()=>{
	  loadPage(next_page.value, true); 
	},2000);
});
/**
 * 模板属性跳转页面
 * @param {Object} e
 */
function goPage(event){
	//topDropDownShow.value=false;
	//console.log(111111);
	uni.$utils.dataSetPage(event);
};
</script>

<style  lang="scss">
	page {
		
	}
.fnow{color:#2979ff;}
</style>
